package cn.netbox.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * description:
 * date: 2022/3/12 13:53
 * author: Alex
 * version: 1.0
 */
@Controller
public class HelloController {
    @RequestMapping("/")
    public String hello() {
        return "hello";
    }

    @RequestMapping("/target")
    public String target(HttpServletRequest request) {
        HttpSession session = request.getSession();
        request.setAttribute("testScope","hello");
        return "target";
    }

    @RequestMapping("/h?llo/index")
    public String index() {
        return "index";
    }

    @RequestMapping("/test/{id}/{name}")
    public String rest(@PathVariable("id") int id, @PathVariable("name") String name) {
        System.out.println("id: " + id + ",name: " + name);
        return "target";
    }

    @RequestMapping("/test")
    public String servlet(HttpServletRequest request) {
        System.out.println("id: " + request.getParameter("id") + ",name: " + request.getParameter("name"));
        return "target";
    }

    @RequestMapping("/test2")
    public String servlet2(String name, int id) {
        System.out.println("id: " + id + ",name: " + name);
        return "target";
    }

    @RequestMapping(value = "/testuser")
    public String testUser(String username, String password, String lesson,
    @CookieValue("JSESSIONID") String JSESSIONID) {
        System.out.println("password: " + password + ",name: " + username + lesson);
        System.out.println(JSESSIONID);
        return "target";
    }

}
